<?php

namespace app\index\controller\consulting;

use app\index\model\UM as UM;
use app\index\service\QuickConsultingServerService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\Request as Request;

/**
 * QuickConsultingServer 控制器
 * Class QuickConsultingServer
 * @package app\index\controller\consulting;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 * @see \app\index\validate\consulting\QuickConsultingServer
 */
class QuickConsultingServer
{
    // 请求参数
    private Request $request;

    // service
    private QuickConsultingServerService $service;

    public function __construct(Request $request, QuickConsultingServerService $quickConsultingServerService)
    {
        $this->request = $request;
        $this->service = $quickConsultingServerService;
    }

    /**
     * 极速咨询-列表
     * @param UM|null $user
     * @return ApiResponse
     * @url /consulting/quick_consulting_server/index
     */
    public function index(?UM $user): ApiResponse
    {
        $request = $this->request;

        $type = $request->param('type', '1');
        $page = $request->param('page', 1);
        $page_size = $request->param('page_size', 3);

        return ApiResponse::success($this->service->index($user, $type, $page, $page_size));
    }

    /**
     * 咨询服务-详情
     * @return ApiResponse
     * @url /consulting/quick_consulting_server/read
     */
    public function read(): ApiResponse
    {
        $request = $this->request;

        $id = $request->param('id');
        // serverType 服务类型 1自定义服务 2免费咨询 3极速咨询 4畅聊 5电话咨询
        $serverType = $request->param('serverType');

        return ApiResponse::success($this->service->read($id, $serverType));
    }
}
